
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/19/2013 14:54:31
-- Generated from EDMX file: C:\Projects\mvclab\Citi.GocAttributes\Citi.GocAttributes.Domain\Database.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [GocAttributes2];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK__Function__Parent__0DAF0CB0]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Function] DROP CONSTRAINT [FK__Function__Parent__0DAF0CB0];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__CountryId__440B1D61]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__CountryId__440B1D61];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__FRSBuId__412EB0B6]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__FRSBuId__412EB0B6];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__FRSOuId__4222D4EF]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__FRSOuId__4222D4EF];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__FunctionId__46E78A0C]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__FunctionId__46E78A0C];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__LevelId__4316F928]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__LevelId__4316F928];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__ManagedSegm__45F365D3]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__ManagedSegm__45F365D3];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__RuleId__44FF419A]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__RuleId__44FF419A];
GO
IF OBJECT_ID(N'[dbo].[FK__GOC__SidId__403A8C7D]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[GOC] DROP CONSTRAINT [FK__GOC__SidId__403A8C7D];
GO
IF OBJECT_ID(N'[dbo].[FK__ImportErr__Impor__1FCDBCEB]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ImportError] DROP CONSTRAINT [FK__ImportErr__Impor__1FCDBCEB];
GO
IF OBJECT_ID(N'[dbo].[FK__ManagedSe__Paren__1273C1CD]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ManagedSegment] DROP CONSTRAINT [FK__ManagedSe__Paren__1273C1CD];
GO
IF OBJECT_ID(N'[dbo].[FK__RuleCondi__Funct__31EC6D26]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RuleCondition] DROP CONSTRAINT [FK__RuleCondi__Funct__31EC6D26];
GO
IF OBJECT_ID(N'[dbo].[FK__RuleCondi__Manag__30F848ED]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RuleCondition] DROP CONSTRAINT [FK__RuleCondi__Manag__30F848ED];
GO
IF OBJECT_ID(N'[dbo].[FK__RuleCondi__RuleI__300424B4]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RuleCondition] DROP CONSTRAINT [FK__RuleCondi__RuleI__300424B4];
GO
IF OBJECT_ID(N'[dbo].[FK__RuleResul__RuleI__36B12243]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RuleResult] DROP CONSTRAINT [FK__RuleResul__RuleI__36B12243];
GO
IF OBJECT_ID(N'[dbo].[FK__RuleResul__TypeR__37A5467C]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RuleResult] DROP CONSTRAINT [FK__RuleResul__TypeR__37A5467C];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Country]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Country];
GO
IF OBJECT_ID(N'[dbo].[FRSBu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FRSBu];
GO
IF OBJECT_ID(N'[dbo].[FRSOu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FRSOu];
GO
IF OBJECT_ID(N'[dbo].[Function]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Function];
GO
IF OBJECT_ID(N'[dbo].[GOC]', 'U') IS NOT NULL
    DROP TABLE [dbo].[GOC];
GO
IF OBJECT_ID(N'[dbo].[ImportError]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ImportError];
GO
IF OBJECT_ID(N'[dbo].[ImportHistory]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ImportHistory];
GO
IF OBJECT_ID(N'[dbo].[Level]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Level];
GO
IF OBJECT_ID(N'[dbo].[ManagedSegment]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ManagedSegment];
GO
IF OBJECT_ID(N'[dbo].[Rule]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Rule];
GO
IF OBJECT_ID(N'[dbo].[RuleCondition]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RuleCondition];
GO
IF OBJECT_ID(N'[dbo].[RuleResult]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RuleResult];
GO
IF OBJECT_ID(N'[dbo].[Sid]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sid];
GO
IF OBJECT_ID(N'[dbo].[TypeRuleResult]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TypeRuleResult];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Countries'
CREATE TABLE [dbo].[Countries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Abbreviation] varchar(5)  NOT NULL,
    [Description] varchar(50)  NOT NULL
);
GO

-- Creating table 'FRSBus'
CREATE TABLE [dbo].[FRSBus] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] int  NOT NULL,
    [Description] varchar(100)  NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'FRSOus'
CREATE TABLE [dbo].[FRSOus] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] int  NOT NULL,
    [Description] varchar(100)  NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'Functions'
CREATE TABLE [dbo].[Functions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] varchar(6)  NOT NULL,
    [Description] varchar(250)  NOT NULL,
    [ParentId] int  NULL,
    [Status] char(1)  NOT NULL,
    [TreeLevel] smallint  NOT NULL,
    [Definition] varchar(2000)  NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'Gocs'
CREATE TABLE [dbo].[Gocs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [GOCAttribute] varchar(20)  NOT NULL,
    [LongDescription] varchar(250)  NOT NULL,
    [Status] char(1)  NOT NULL,
    [UpdatedDate] datetime  NULL,
    [SidId] int  NOT NULL,
    [LocalCostCode] varchar(10)  NOT NULL,
    [Manager] varchar(7)  NOT NULL,
    [FRSBuId] int  NOT NULL,
    [FRSOuId] int  NOT NULL,
    [FunctionId] int  NOT NULL,
    [LevelId] int  NOT NULL,
    [CountryId] int  NOT NULL,
    [ManagedSegmentId] int  NOT NULL,
    [ExpenseCode] varchar(20)  NULL,
    [CorpCode] varchar(20)  NULL,
    [RuleId] int  NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'ImportErrors'
CREATE TABLE [dbo].[ImportErrors] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ImportHistoryId] int  NOT NULL,
    [Line] int  NOT NULL,
    [Error] varchar(2000)  NOT NULL,
    [Fields] varchar(8000)  NULL
);
GO

-- Creating table 'ImportHistories'
CREATE TABLE [dbo].[ImportHistories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FileName] varchar(255)  NOT NULL,
    [UploadDate] datetime  NOT NULL
);
GO

-- Creating table 'Levels'
CREATE TABLE [dbo].[Levels] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] varchar(10)  NOT NULL,
    [Description] varchar(250)  NOT NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'ManagedSegments'
CREATE TABLE [dbo].[ManagedSegments] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] int  NOT NULL,
    [Description] varchar(250)  NOT NULL,
    [ParentId] int  NULL,
    [TreeLevel] int  NOT NULL,
    [UpdatedDate] datetime  NOT NULL,
    [Status] char(1)  NOT NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'Rules'
CREATE TABLE [dbo].[Rules] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL,
    [Active] bit  NOT NULL,
    [Exception] bit  NOT NULL,
    [Name] varchar(50)  NOT NULL
);
GO

-- Creating table 'RuleConditions'
CREATE TABLE [dbo].[RuleConditions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RuleId] int  NULL,
    [Type] smallint  NULL,
    [ManagedSegmentId] int  NULL,
    [FunctionId] int  NULL,
    [Level] int  NULL,
    [Value] varchar(200)  NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'RuleResults'
CREATE TABLE [dbo].[RuleResults] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RuleId] int  NOT NULL,
    [TypeRuleResultId] int  NOT NULL
);
GO

-- Creating table 'Sids'
CREATE TABLE [dbo].[Sids] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] varchar(10)  NOT NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- Creating table 'TypeRuleResults'
CREATE TABLE [dbo].[TypeRuleResults] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] smallint  NOT NULL,
    [Value] varchar(80)  NULL,
    [Active] bit  NOT NULL,
    [ReferenceDate] datetime  NOT NULL,
    [LastUpdate] datetime  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Countries'
ALTER TABLE [dbo].[Countries]
ADD CONSTRAINT [PK_Countries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FRSBus'
ALTER TABLE [dbo].[FRSBus]
ADD CONSTRAINT [PK_FRSBus]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FRSOus'
ALTER TABLE [dbo].[FRSOus]
ADD CONSTRAINT [PK_FRSOus]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Functions'
ALTER TABLE [dbo].[Functions]
ADD CONSTRAINT [PK_Functions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [PK_GOCs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ImportErrors'
ALTER TABLE [dbo].[ImportErrors]
ADD CONSTRAINT [PK_ImportErrors]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ImportHistories'
ALTER TABLE [dbo].[ImportHistories]
ADD CONSTRAINT [PK_ImportHistories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Levels'
ALTER TABLE [dbo].[Levels]
ADD CONSTRAINT [PK_Levels]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ManagedSegments'
ALTER TABLE [dbo].[ManagedSegments]
ADD CONSTRAINT [PK_ManagedSegments]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Rules'
ALTER TABLE [dbo].[Rules]
ADD CONSTRAINT [PK_Rules]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RuleConditions'
ALTER TABLE [dbo].[RuleConditions]
ADD CONSTRAINT [PK_RuleConditions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RuleResults'
ALTER TABLE [dbo].[RuleResults]
ADD CONSTRAINT [PK_RuleResults]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Sids'
ALTER TABLE [dbo].[Sids]
ADD CONSTRAINT [PK_Sids]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TypeRuleResults'
ALTER TABLE [dbo].[TypeRuleResults]
ADD CONSTRAINT [PK_TypeRuleResults]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CountryId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__CountryId__440B1D61]
    FOREIGN KEY ([CountryId])
    REFERENCES [dbo].[Countries]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__CountryId__440B1D61'
CREATE INDEX [IX_FK__GOC__CountryId__440B1D61]
ON [dbo].[Gocs]
    ([CountryId]);
GO

-- Creating foreign key on [FRSBuId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__FRSBuId__412EB0B6]
    FOREIGN KEY ([FRSBuId])
    REFERENCES [dbo].[FRSBus]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__FRSBuId__412EB0B6'
CREATE INDEX [IX_FK__GOC__FRSBuId__412EB0B6]
ON [dbo].[Gocs]
    ([FRSBuId]);
GO

-- Creating foreign key on [FRSOuId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__FRSOuId__4222D4EF]
    FOREIGN KEY ([FRSOuId])
    REFERENCES [dbo].[FRSOus]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__FRSOuId__4222D4EF'
CREATE INDEX [IX_FK__GOC__FRSOuId__4222D4EF]
ON [dbo].[Gocs]
    ([FRSOuId]);
GO

-- Creating foreign key on [ParentId] in table 'Functions'
ALTER TABLE [dbo].[Functions]
ADD CONSTRAINT [FK__Function__Parent__0DAF0CB0]
    FOREIGN KEY ([ParentId])
    REFERENCES [dbo].[Functions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__Function__Parent__0DAF0CB0'
CREATE INDEX [IX_FK__Function__Parent__0DAF0CB0]
ON [dbo].[Functions]
    ([ParentId]);
GO

-- Creating foreign key on [FunctionId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__FunctionId__46E78A0C]
    FOREIGN KEY ([FunctionId])
    REFERENCES [dbo].[Functions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__FunctionId__46E78A0C'
CREATE INDEX [IX_FK__GOC__FunctionId__46E78A0C]
ON [dbo].[Gocs]
    ([FunctionId]);
GO

-- Creating foreign key on [FunctionId] in table 'RuleConditions'
ALTER TABLE [dbo].[RuleConditions]
ADD CONSTRAINT [FK__RuleCondi__Funct__31EC6D26]
    FOREIGN KEY ([FunctionId])
    REFERENCES [dbo].[Functions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__RuleCondi__Funct__31EC6D26'
CREATE INDEX [IX_FK__RuleCondi__Funct__31EC6D26]
ON [dbo].[RuleConditions]
    ([FunctionId]);
GO

-- Creating foreign key on [LevelId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__LevelId__4316F928]
    FOREIGN KEY ([LevelId])
    REFERENCES [dbo].[Levels]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__LevelId__4316F928'
CREATE INDEX [IX_FK__GOC__LevelId__4316F928]
ON [dbo].[Gocs]
    ([LevelId]);
GO

-- Creating foreign key on [ManagedSegmentId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__ManagedSegm__45F365D3]
    FOREIGN KEY ([ManagedSegmentId])
    REFERENCES [dbo].[ManagedSegments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__ManagedSegm__45F365D3'
CREATE INDEX [IX_FK__GOC__ManagedSegm__45F365D3]
ON [dbo].[Gocs]
    ([ManagedSegmentId]);
GO

-- Creating foreign key on [RuleId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__RuleId__44FF419A]
    FOREIGN KEY ([RuleId])
    REFERENCES [dbo].[Rules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__RuleId__44FF419A'
CREATE INDEX [IX_FK__GOC__RuleId__44FF419A]
ON [dbo].[Gocs]
    ([RuleId]);
GO

-- Creating foreign key on [SidId] in table 'Gocs'
ALTER TABLE [dbo].[Gocs]
ADD CONSTRAINT [FK__GOC__SidId__403A8C7D]
    FOREIGN KEY ([SidId])
    REFERENCES [dbo].[Sids]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__GOC__SidId__403A8C7D'
CREATE INDEX [IX_FK__GOC__SidId__403A8C7D]
ON [dbo].[Gocs]
    ([SidId]);
GO

-- Creating foreign key on [ImportHistoryId] in table 'ImportErrors'
ALTER TABLE [dbo].[ImportErrors]
ADD CONSTRAINT [FK__ImportErr__Impor__1FCDBCEB]
    FOREIGN KEY ([ImportHistoryId])
    REFERENCES [dbo].[ImportHistories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__ImportErr__Impor__1FCDBCEB'
CREATE INDEX [IX_FK__ImportErr__Impor__1FCDBCEB]
ON [dbo].[ImportErrors]
    ([ImportHistoryId]);
GO

-- Creating foreign key on [ParentId] in table 'ManagedSegments'
ALTER TABLE [dbo].[ManagedSegments]
ADD CONSTRAINT [FK__ManagedSe__Paren__1273C1CD]
    FOREIGN KEY ([ParentId])
    REFERENCES [dbo].[ManagedSegments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__ManagedSe__Paren__1273C1CD'
CREATE INDEX [IX_FK__ManagedSe__Paren__1273C1CD]
ON [dbo].[ManagedSegments]
    ([ParentId]);
GO

-- Creating foreign key on [ManagedSegmentId] in table 'RuleConditions'
ALTER TABLE [dbo].[RuleConditions]
ADD CONSTRAINT [FK__RuleCondi__Manag__30F848ED]
    FOREIGN KEY ([ManagedSegmentId])
    REFERENCES [dbo].[ManagedSegments]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__RuleCondi__Manag__30F848ED'
CREATE INDEX [IX_FK__RuleCondi__Manag__30F848ED]
ON [dbo].[RuleConditions]
    ([ManagedSegmentId]);
GO

-- Creating foreign key on [RuleId] in table 'RuleConditions'
ALTER TABLE [dbo].[RuleConditions]
ADD CONSTRAINT [FK__RuleCondi__RuleI__300424B4]
    FOREIGN KEY ([RuleId])
    REFERENCES [dbo].[Rules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__RuleCondi__RuleI__300424B4'
CREATE INDEX [IX_FK__RuleCondi__RuleI__300424B4]
ON [dbo].[RuleConditions]
    ([RuleId]);
GO

-- Creating foreign key on [RuleId] in table 'RuleResults'
ALTER TABLE [dbo].[RuleResults]
ADD CONSTRAINT [FK__RuleResul__RuleI__36B12243]
    FOREIGN KEY ([RuleId])
    REFERENCES [dbo].[Rules]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__RuleResul__RuleI__36B12243'
CREATE INDEX [IX_FK__RuleResul__RuleI__36B12243]
ON [dbo].[RuleResults]
    ([RuleId]);
GO

-- Creating foreign key on [TypeRuleResultId] in table 'RuleResults'
ALTER TABLE [dbo].[RuleResults]
ADD CONSTRAINT [FK__RuleResul__TypeR__37A5467C]
    FOREIGN KEY ([TypeRuleResultId])
    REFERENCES [dbo].[TypeRuleResults]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK__RuleResul__TypeR__37A5467C'
CREATE INDEX [IX_FK__RuleResul__TypeR__37A5467C]
ON [dbo].[RuleResults]
    ([TypeRuleResultId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------